home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Q: realloc->free?
- Date: Tue, 16 Jan 96 16:19:37 GMT
- Organization: none
- Message-ID: <821809177snz@genesis.demon.co.uk>
- References: <4daa2e$oh5@axe.netdoor.com> <4de8uv$48j@bs33n.staffs.ac.uk>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4de8uv$48j@bs33n.staffs.ac.uk>
- cm4bctrd@bs47c.staffs.ac.uk "Wildfire" writes:
-
- >: b = realloc(a, 100);
-
- ...
-
- >If you think about it, there is no need for realloc() to move the *start*
- >of the allocated memory - it may need to make a link between the end of
- >the original memory block and the start of an extension block, but that's
- >different.
-
- What do you mean by 'make a link'? The block of memory returned by realloc
- must be contiguous so that, for example, you can treat it like an array
- and access all elements using pointer arithmetic.
-
- >So b is either going to be NULL or a.
-
- Never assume in a program that b will equal a - it can and does change in
- implementations even when the allocation size is being reduced (some
- allcation schemes will allocate from different internal tables depending
- on the allocation size, a realloc may require a shift from one table
- to another on any change in size).
-
- >realloc() does no free()ing, as far as I know, since the contents of
- >memory are unchanged.
-
- It releases unneeded space when you redude the allocation size and is
- equivalent to free when the allocation size is zero.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-